﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Transactions;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using DotNetOpenAuth.AspNet;
using Microsoft.Web.WebPages.OAuth;
using WebMatrix.WebData;
//using Hotel_application.Filters;
using Hotel_application.Models;


namespace Hotel_application.Controllers
{
    public class AdministratorController : Controller
    {
        //
        // GET: /Administrator/
        public ActionResult LogOn()
        {
            return View();
        }

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult LogOn(Models.TaiKhoan model, string returnUrl)
        {
            var ks = new KhachSanEntities();
            if (ModelState.IsValid)
            {
                if (ks.proc_DangNhap(model.maTK, model.passwordTK).FirstOrDefault() == 1)
                {
                    FormsAuthentication.SetAuthCookie(model.maTK, true);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                   ModelState.AddModelError("", "Xin vui lòng nhập lại");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

        public ActionResult LogOff()
        {
            FormsAuthentication.SignOut();

            return RedirectToAction("Index", "Home");
        }






    }
}
